<template>
  <view class="form-item-time">
    <wd-input v-bind="$attrs" clearable v-model="localValue" readonly @click="onClick" />

    <VGeneralPicker
      :title="title"
      v-model:value="defaultValue"
      v-model:visible="visible"
      @update:value="onUpdateVal"
      :options="options"
    />
  </view>
</template>

<script lang="ts" setup>
import VGeneralPicker from '../Popup/GeneralPicker.vue'
interface Props {
  title: string
  value: any
  options: Array<{
    label: string
    value: string
    disabled?: boolean
  }>
}

const defaultValue = ref('1')
const visible = ref(false)

const props = withDefaults(defineProps<Props>(), {})

const emit = defineEmits<{
  'update:value': [value: string]
}>()
const localValue = computed({
  get: () => {
    return props.value
  },
  set: (val) => {
    emit('update:value', val)
  },
})

function onClick() {
  visible.value = true
}

const onUpdateVal = ({ value, label }) => {
  emit('update:value', value)
  localValue.value = label
  defaultValue.value = value
}
</script>

<style lang="scss" scoped>
.form-item-time {
  .wd-input__body {
    text-align: right;
  }
}
</style>
